package com.fumihiko.modules.jxxm.controller;

import java.util.*;

import com.fumihiko.modules.jxxm.entity.RetiredEmployeesEntity;
import com.fumihiko.modules.sys.entity.SysDictEntity;
import com.fumihiko.modules.sys.service.SysDictService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fumihiko.modules.jxxm.entity.AllEntity;
import com.fumihiko.modules.jxxm.service.AllService;
import com.fumihiko.common.utils.PageUtils;
import com.fumihiko.common.utils.R;



/**
 * VIEW
 *
 * @author hanwenpeng
 * @email devilzwy@gmail.com
 * @date 2022-04-18 10:03:50
 */
@RestController
@RequestMapping("jxxm/all")
public class AllController {
    @Autowired
    private AllService allService;

    @Autowired
    private SysDictService sysDictService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("jxxm:all:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = allService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 查询列表
     */
    @RequestMapping("/searchList")
    @RequiresPermissions("jxxm:all:searchList")
    public R searchList(@RequestParam Map<String, Object> params){
        PageUtils page = allService.searchPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{areaCode}")
    @RequiresPermissions("jxxm:all:info")
    public R info(@PathVariable("areaCode") String areaCode){
		AllEntity all = allService.getById(areaCode);

        return R.ok().put("all", all);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("jxxm:all:save")
    public R save(@RequestBody AllEntity all){
		allService.save(all);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("jxxm:all:update")
    public R update(@RequestBody AllEntity all){
		allService.updateById(all);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("jxxm:all:delete")
    public R delete(@RequestBody String[] areaCodes){
		allService.removeByIds(Arrays.asList(areaCodes));

        return R.ok();
    }

    /**
     * 统计分析饼x,y轴数据
     */
    @RequestMapping("/xAxis/{type}")
    @RequiresPermissions("jxxm:all:xAxis")
    public R xAxis(@PathVariable("type") String type,@RequestParam Map<String, Object> params){
        String area = (String)params.get("area");
        String personType = (String)params.get("personType");
        List<AllEntity> list = allService.getTypeNum(type,area,personType);
        List<SysDictEntity> listDict = sysDictService.listByType(type);
        List<Object> ints = new ArrayList<>();
        Map<String, Object> tempMap = new HashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            if(type.equals("BRZT"))
            {
                tempMap.put(list.get(i).getMyStatus(),list.get(i).getTeachingAge());
            }else if(type.equals("ZZMM")){
                tempMap.put(list.get(i).getPoliticalFace(),list.get(i).getTeachingAge());
            }else if(type.equals("NATION")){
                tempMap.put(list.get(i).getNation(),list.get(i).getTeachingAge());
            }else if(type.equals("SEX_GROUP")){
                tempMap.put(list.get(i).getSex(),list.get(i).getTeachingAge());
            }else if(type.equals("TXQSF")){
                tempMap.put(list.get(i).getRetirementStatus(),list.get(i).getTeachingAge());
            }else if(type.equals("TXSZW")){
                tempMap.put(list.get(i).getDuties(),list.get(i).getTeachingAge());
            }else if(type.equals("EMPLOYEE")){
                tempMap.put(list.get(i).getWorkersClassification(),list.get(i).getTeachingAge());
            }else if(type.equals("YJSJD")){
                tempMap.put(list.get(i).getHandoverPeriod(),list.get(i).getTeachingAge());
            }else if(type.equals("YBD")){
                tempMap.put(list.get(i).getOriginalTroops(),list.get(i).getTeachingAge());
            }else if(type.equals("STREET")){
                tempMap.put(list.get(i).getStreet(),list.get(i).getTeachingAge());
            }else if(type.equals("AREA")){
                tempMap.put(list.get(i).getCounty(),list.get(i).getTeachingAge());
            }
        }
        for (int i = 0; i <listDict.size() ; i++) {
            if(tempMap.containsKey(listDict.get(i).getValue()))
            {
                ints.add(listDict.get(i).getValue());
            }
        }

        return R.ok().put("list", ints);

    }

    /**
     * 统计分析柱状图数据
     */
    @RequestMapping("/select/{type}")
    @RequiresPermissions("jxxm:all:select")
    public R select(@PathVariable("type") String type,@RequestParam Map<String, Object> params){
        String area = (String)params.get("area");
        String personType = (String)params.get("personType");
        List<AllEntity> list = allService.getTypeNum(type,area,personType);
        List<SysDictEntity> listDict = sysDictService.listByType(type);
        List<Object> ints = new ArrayList<>();
        Map<String, Object> tempMap = new HashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            if(type.equals("BRZT"))
            {
                tempMap.put(list.get(i).getMyStatus(),list.get(i).getTeachingAge());
            }else if(type.equals("ZZMM")){
                tempMap.put(list.get(i).getPoliticalFace(),list.get(i).getTeachingAge());
            }else if(type.equals("NATION")){
                tempMap.put(list.get(i).getNation(),list.get(i).getTeachingAge());
            }else if(type.equals("SEX_GROUP")){
                tempMap.put(list.get(i).getSex(),list.get(i).getTeachingAge());
            }else if(type.equals("TXQSF")){
                tempMap.put(list.get(i).getRetirementStatus(),list.get(i).getTeachingAge());
            }else if(type.equals("TXSZW")){
                tempMap.put(list.get(i).getDuties(),list.get(i).getTeachingAge());
            }else if(type.equals("EMPLOYEE")){
                tempMap.put(list.get(i).getWorkersClassification(),list.get(i).getTeachingAge());
            }else if(type.equals("YJSJD")){
                tempMap.put(list.get(i).getHandoverPeriod(),list.get(i).getTeachingAge());
            }else if(type.equals("YBD")){
                tempMap.put(list.get(i).getOriginalTroops(),list.get(i).getTeachingAge());
            }else if(type.equals("STREET")){
                tempMap.put(list.get(i).getStreet(),list.get(i).getTeachingAge());
            }else if(type.equals("AREA")){
                tempMap.put(list.get(i).getCounty(),list.get(i).getTeachingAge());
            }

        }
        for (int i = 0; i <listDict.size() ; i++) {
            if(tempMap.containsKey(listDict.get(i).getValue()))
            {
                ints.add(tempMap.get(listDict.get(i).getValue()));
            }
        }
        return R.ok().put("list", ints);
    }

    /**
     * 统计分析饼状图数据
     */
    @RequestMapping("/pie/{type}")
    @RequiresPermissions("jxxm:all:pie")
    public R pie(@PathVariable("type") String type,@RequestParam Map<String, Object> params){
        String area = (String)params.get("area");
        String personType = (String)params.get("personType");
        List<AllEntity> list = allService.getTypeNum(type,area,personType);
        //List<SysDictEntity> listDict = sysDictService.listByType(type);
        List<Map<String, Object>> listaa = new ArrayList<>();
        Map<String, Object> tempMap = new LinkedHashMap<>();
        for (int i = 0; i <list.size() ; i++) {
            if(type.equals("BRZT"))
            {
                tempMap.put(list.get(i).getMyStatus(),list.get(i).getTeachingAge());
            }else if(type.equals("ZZMM")){
                tempMap.put(list.get(i).getPoliticalFace(),list.get(i).getTeachingAge());
            }else if(type.equals("NATION")){
                tempMap.put(list.get(i).getNation(),list.get(i).getTeachingAge());
            }else if(type.equals("SEX_GROUP")){
                tempMap.put(list.get(i).getSex(),list.get(i).getTeachingAge());
            }else if(type.equals("TXQSF")){
                tempMap.put(list.get(i).getRetirementStatus(),list.get(i).getTeachingAge());
            }else if(type.equals("TXSZW")){
                tempMap.put(list.get(i).getDuties(),list.get(i).getTeachingAge());
            }else if(type.equals("EMPLOYEE")){
                tempMap.put(list.get(i).getWorkersClassification(),list.get(i).getTeachingAge());
            }else if(type.equals("YJSJD")){
                tempMap.put(list.get(i).getHandoverPeriod(),list.get(i).getTeachingAge());
            }else if(type.equals("YBD")){
                tempMap.put(list.get(i).getOriginalTroops(),list.get(i).getTeachingAge());
            }else if(type.equals("STREET")){
                tempMap.put(list.get(i).getStreet(),list.get(i).getTeachingAge());
            }else if(type.equals("AREA")){
                tempMap.put(list.get(i).getCounty(),list.get(i).getTeachingAge());
            }
        }
//        for (int i = 0; i <listDict.size() ; i++) {
//            Map<String, Object> map11 = new LinkedHashMap<>();
//
//
//            if(tempMap.containsKey(listDict.get(i).getValue()))
//            {
//
//                map11.put("name",listDict.get(i).getValue());
//                map11.put("value",tempMap.get(listDict.get(i).getValue()));
//                listaa.add(map11);
//            }
//        }
        Set set = tempMap.keySet();
        for (Object o : set) {
            List<SysDictEntity> listName = sysDictService.listByName(o.toString());
            if(listName.size() > 0)
            {
                Map<String, Object> map11 = new LinkedHashMap<>();
                map11.put("name",o);
                map11.put("value",tempMap.get(o));
                listaa.add(map11);
            }
        }
        return R.ok().put("list", listaa);
    }

    /**
     * 地图点击事件
     */
    @RequestMapping("/map/{contrys}")
    @RequiresPermissions("jxxm:all:map")
    public R map(@PathVariable("contrys") String contrys,@RequestParam Map<String, Object> params){
        String personType = (String)params.get("personType");
        List<Map<String, Object>> listaa = new ArrayList<>();
        List<AllEntity> list = allService.getStreetByContry(contrys,personType);
        for (int i = 0; i < list.size(); i++) {
            Map<String, Object> tempMap = new HashMap<>();
            tempMap.put("name",list.get(i).getStreet());
            tempMap.put("value",list.get(i).getTeachingAge());
            listaa.add(tempMap);
        }
        return R.ok().put("list", listaa);

    }

}
